﻿// This source file is part of WallpaperControl, a tool for automatic changing 
// of the desktop wallpaper.
// 
// Visit http://wpcontrol.sourceforge.net/ for more.
//
// Copyright (c) 2014 nscrolldev
//
// Licensed under the GPLv2.
// See http://www.gnu.org/licenses/gpl-2.0.html for details.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WallpaperControl
{
    /// <summary>
    /// Contains all settings for WallpaperControl.
    /// </summary>
    class Configuration
    {
        /// <summary>
        /// Creates a new configuration. This loads the default values.
        /// </summary>
        public Configuration()
        {
            this.StartWithWindows = true;
            this.StartWithControlPanel = true;

            this.ChangeInfo = true;
            this.RunningInfo = true;
            this.LoopingInfo = false;

            this.LoopWallpapers = false;

            this.OldConfig = this;
        }

        /// <summary>
        /// Creates a new configuration with the given values.
        /// </summary>
        /// <param name="autoStart">
        /// True if WallpaperControl should start automatically with Windows.
        /// </param>
        /// <param name="cpanelStart">
        /// True if WallpaperControl should start with showing the ControlPanel.
        /// </param>
        /// <param name="infoOnChange">
        /// True if a tooltip should be displayed when the wallpaper is changed.
        /// </param>
        /// <param name="infoIfRunning">
        /// True if a tooltip should be displayed when WallpaperControl is running 
        /// in background.
        /// </param>
        /// <param name="infoOnLoop">
        /// True if a tooltip should be displayed when a loop is performed.
        /// </param>
        /// <param name="loop">
        /// True if WallpaperControl should loop the wallpapers.
        /// </param>
        public Configuration(bool autoStart, bool cpanelStart, bool infoOnChange, bool infoIfRunning, bool infoOnLoop, bool loop)
        {
            this.StartWithWindows = autoStart;
            this.StartWithControlPanel = cpanelStart;

            this.ChangeInfo = infoOnChange;
            this.RunningInfo = infoIfRunning;
            this.LoopingInfo = infoOnLoop;

            this.LoopWallpapers = loop;

            this.OldConfig = this;
        }

        #region Settings
        /// <summary>
        /// Indicates whether WallpaperControl should start with windows.
        /// </summary>
        private bool _startWithWindows;
        /// <summary>
        /// Indicates whether WallpaperControl should start with showing the 
        /// ControlPanel.
        /// </summary>
        private bool _startWithControlPanel;

        /// <summary>
        /// Indicates whether a balloontip is shown when a wallpaper is changed.
        /// </summary>
        private bool _changeInfo;
        /// <summary>
        /// Indicates whether a ballontip should be shown when WallpaperControl starts 
        /// running in background.
        /// </summary>
        private bool _runningInfo;
        /// <summary>
        /// Indicates whether a ballontip should be shown when WallpaperControl
        /// performs a loop. Only if looping is enabled.
        /// </summary>
        /// <seealso cref="Program.SettingsManager.LoopWallpaper"/>
        private bool _loopingInfo;

        /// <summary>
        /// Indicates whether WallpaperControl should start at the beginning of the image 
        /// list if the end was reached.
        /// </summary>
        private bool _loopWallpapers;

        /// <summary>
        /// Holds the obsolete configuration that can be restored.
        /// </summary>
        private Configuration _oldConfig;

        /// <summary>
        /// Gets or sets whether WallpaperControl should start with with windows.
        /// </summary>
        internal bool StartWithWindows
        {
            get
            {
                return this._startWithWindows;
            }
            set
            {
                this._startWithWindows = value;
            }
        }

        /// <summary>
        /// Gets or sets whether WallpaperControl should start with opening 
        /// the ControlPanel.
        /// </summary>
        internal bool StartWithControlPanel
        {
            get
            {
                return this._startWithControlPanel;
            }
            set
            {
                this._startWithControlPanel = value;
            }
        }

        /// <summary>
        /// Gets or sets whether a tooltip should be displayed when the 
        /// wallpaper is changed.
        /// </summary>
        internal bool ChangeInfo
        {
            get
            {
                return this._changeInfo;
            }
            set
            {
                this._changeInfo = value;
            }
        }

        /// <summary>
        /// Gets or sets whether a tooltip should be displayed when WallpaperControl 
        /// is running in background.
        /// </summary>
        internal bool RunningInfo
        {
            get
            {
                return this._runningInfo;
            }
            set
            {
                this._runningInfo = value;
            }
        }

        /// <summary>
        /// Gets or sets whether a tooltip should be displayed when the wallpaper 
        /// list is repeating.
        /// </summary>
        internal bool LoopingInfo
        {
            get
            {
                return this._loopingInfo;
            }
            set
            {
                this._loopingInfo = value;
            }
        }

        /// <summary>
        /// Gets or sets whether whether the list should start again with the first
        /// image when the last wallpaper was reached.
        /// </summary>
        internal bool LoopWallpapers
        {
            get
            {
                return this._loopWallpapers;
            }
            set
            {
                this._loopWallpapers = value;
            }
        }
        #endregion

        /// <summary>
        /// Gets or sets the old configuration.
        /// </summary>
        private Configuration OldConfig
        {
            get
            {
                return this._oldConfig;
            }
            set
            {
                this._oldConfig = value;
            }
        }

        /// <summary>
        /// Gets whether this configuration has been changed.
        /// </summary>
        private bool Changed
        {
            get
            {
                if (
                    this.StartWithWindows == this.OldConfig.StartWithWindows &&
                    this.StartWithControlPanel == this.OldConfig.StartWithControlPanel &&
                    this.ChangeInfo == this.OldConfig.ChangeInfo &&
                    this.RunningInfo == this.OldConfig.RunningInfo &&
                    this.LoopingInfo == this.OldConfig.LoopingInfo &&
                    this.LoopWallpapers == this.OldConfig.LoopWallpapers
                   )
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }

        /// <summary>
        /// Loads the default configuration values.
        /// </summary>
        internal void LoadDefaults()
        {
            this.StartWithWindows = true;
            this.StartWithControlPanel = true;

            this.ChangeInfo = true;
            this.RunningInfo = true;
            this.LoopingInfo = false;

            this.LoopWallpapers = false;
        }

        /// <summary>
        /// Loads the configuration from a file.
        /// </summary>
        internal void Load()
        {
        }

        /// <summary>
        /// Saves the configuration into a file.
        /// </summary>
        internal void Save()
        {
        }

        /// <summary>
        /// Restores the old configuration. Used if the new config is aborted.
        /// </summary>
        internal void Restore()
        {
            if (this.OldConfig != null)
            {
                this.StartWithWindows = this.OldConfig.StartWithWindows;
                this.StartWithControlPanel = this.OldConfig.StartWithControlPanel;
                this.ChangeInfo = this.OldConfig.ChangeInfo;
                this.RunningInfo = this.OldConfig.RunningInfo;
                this.LoopingInfo = this.OldConfig.LoopingInfo;
                this.LoopWallpapers = this.OldConfig.LoopWallpapers;
            }
        }
    }
}
